package com.qingpeng.pay.fragment;

import com.qingpeng.pay.R;
import com.qingpeng.pay.activity.MoneyListActivity;
import com.qingpeng.pay.adapter.QRCodelistAdapter;
import com.qingpeng.pay.api.Host;
import com.qingpeng.pay.api.RedBag;
import com.qingpeng.pay.base.BaseFragment;
import com.qingpeng.pay.beans.QRCodeListBean;
import com.qingpeng.pay.okhttp.RetrofitCreateHelper;
import com.qingpeng.pay.utils.ToastUtils;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class FenPeiFragment extends BaseFragment {
    private List<QRCodeListBean.DataProductBean.PaofenProductBean> mList;
    @Override
    protected int getLayoutId() {
        return R.layout.fragment_notice_list;
    }

    @Override
    protected int getRefreshId() {
        return 0;
    }

    @Override
    protected int getListViewId() {
        return R.id.recycler;
    }

    @Override
    public void onResume() {
        super.onResume();
        String id = getActivity().getIntent().getStringExtra("id");
        Call<QRCodeListBean> nullBeanCall = RetrofitCreateHelper.createApi(RedBag.class, Host.HOST).erweima_info(id);
        nullBeanCall.enqueue(new Callback<QRCodeListBean>() {
            @Override
            public void onResponse(Call<QRCodeListBean> call, Response<QRCodeListBean> response) {
                QRCodeListBean body = response.body();
                if (body.getStatus() != 1) {
                    ToastUtils.showToast(mContext, body.getInfo());
                    return;
                }
                List<QRCodeListBean.DataProductBean.PaofenProductBean> fenpei = body.getData().getFenpei();
                List<QRCodeListBean.DataProductBean.PaofenProductBean> paofen = body.getData().getPaofen();
                mList=new ArrayList<>();
                if (fenpei!=null){
                    mList.addAll(fenpei);
                }
                initAdapter();
            }

            @Override
            public void onFailure(Call<QRCodeListBean> call, Throwable t) {

            }
        });
    }

    @Override
    protected void initAdapter() {
        mAdapter = new QRCodelistAdapter(R.layout.item_money_list);
        mAdapter.setNewData(mList);
        super.initAdapter();
    }
}
